import React, { useState } from 'react'
import MarkdownIt from 'markdown-it'
import MdEditor from 'react-markdown-editor-lite'
import 'react-markdown-editor-lite/lib/index.css'
export default function Md() {
    // 用来解析 md 用的
    const md = new MarkdownIt()
    const [htmlStr, setHtmlStr] = useState('')
    // 解构
    const changeContent = ({ html, text }) => {
        // 将该内容提交到服务器保存
        console.log(html, text);
        // 获取到当前输入的内容
        setHtmlStr(html)
    }
    return (
        <div>
            <MdEditor style={{ height: 500 }} renderHTML={text => md.render(text)} onChange={changeContent} ></MdEditor>

            <div dangerouslySetInnerHTML={{ __html: htmlStr }}></div>
        </div>
    )
}
